
#include <stdio.h>
#include "STLOG.h"
#include "STL_HttpServer.h"
#include "STL_Json.h"
#include <unistd.h>

using namespace STL;

int main(int argc, char *argv[])
{
    STL_HttpServer::HttpServerConfig config("0.0.0.0", 1033);
    STL_HttpServer *server = new STL_HttpServer(config);
    server->addHandler("/version",[](std::shared_ptr<STL_HttpRequest> req, std::shared_ptr<STL_HttpResponse> res,std::function<void(void)> callback){
        res->setBody(std::string("1.0.0"));
        callback();
    });
    server->addHandler("/test",[](std::shared_ptr<STL_HttpRequest> req, std::shared_ptr<STL_HttpResponse> res,std::function<void(void)> callback){
        JSONCPP::Value j_res;
        j_res["status"] = 0;
        j_res["data"] = "test";
        res->setBodyFromJson(j_res);
        callback();
    });
    stlog_debug("Hello World!\n");
    while (1)
    {
        stlog_debug("...\n");
        sleep(1);
    }
    return 0;
}
